<!--#
layout("/layouts/platform.html"){
#-->
<style>
    .el-upload input[type=file] {
        display: none;
    }

    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 128px;
        height: 128px;
        line-height: 128px;
        text-align: center;
    }

    .avatar {
        width: 128px;
        height: 128px;
        display: block;
    }
</style>
<div id="app" v-cloak>
    <el-row class="header navbar bg-white shadow">
        <!--搜索框-->
        <div class="btn-group tool-button mt5">
            <el-input v-model="pageForm.searchKeyword" @keyup.enter.native="doSearch" placeholder="支付方式、币种"
                      size="medium"></el-input>
        </div>
        <!--搜索按钮-->
        <div class="btn-group tool-button mt5">
            <el-button slot="append" icon="el-icon-search" @click="doSearch" size="medium"></el-button>
        </div>
        <div class="pull-right offscreen-right mt5">
            <el-button size="medium" @click="openAdd"><i class="ti-plus"></i>添加支付方式</el-button>
        </div>
    </el-row>
    <el-row class="el-table-container">
        <el-table
                :data="tableData"
                size="small"
                header-align="center"
                style="width: 100%"
        >
            <!--logo-->
            <el-table-column
                    prop="logo"
                    label="logo"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
                <template scope="scope">
                    <p v-if="scope.row.logo">
                        <img :src="scope.row.logo" style="width: 60px;height: 60px">
                    </p>
                    <p v-else>
                        暂无数据
                    </p>
                </template>
            </el-table-column>
            <!--支付方式-->
            <el-table-column
                    prop="payWay"
                    label="支付方式"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <!--币种-->
            <el-table-column
                    sortable
                    prop="currencyName"
                    label="币种名称"
                    header-align="center"
                    align="center">
                <template slot-scope="scope">
                    {{scope.row.currencyName + '(' + scope.row.remark + ')'}}
                </template>
            </el-table-column>
            <!--序号-->
            <el-table-column
                    prop="sort"
                    label="序号"
                    header-align="center"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="minRechargeAmount"
                    label="最低充值金额"
                    header-align="center"
                    align="center">
                <template slot-scope="scope">
                    {{scope.row.minRechargeAmount == null ? '不限': scope.row.minRechargeAmount}}
                </template>
            </el-table-column>
            <el-table-column
                    prop="maxRechargeAmount"
                    label="最高充值金额"
                    header-align="center"
                    align="center">
                <template slot-scope="scope">
                    {{scope.row.maxRechargeAmount == null ? '不限': scope.row.maxRechargeAmount}}
                </template>
            </el-table-column>
            <el-table-column
                    prop="minWithDrawAmount"
                    label="最低提现金额"
                    header-align="center"
                    align="center">
                <template slot-scope="scope">
                    {{scope.row.minWithDrawAmount == null ? '不限': scope.row.minWithDrawAmount}}
                </template>
            </el-table-column>
            <el-table-column
                    prop="maxWithDrawAmount"
                    label="最高提现金额"
                    header-align="center"
                    align="center">
                <template slot-scope="scope">
                    {{scope.row.maxWithDrawAmount == null ? '不限': scope.row.maxWithDrawAmount}}
                </template>
            </el-table-column>
            <!--支付方式状态-->
            <el-table-column
                    sortable
                    prop="disabled"
                    label="禁用状态"
                    header-align="center"
                    align="center">
                <template slot-scope="scope">
                    <i v-if="scope.row.disabled" class="fa fa-circle text-danger ml5"></i>
                    <i v-if="!scope.row.disabled" class="fa fa-circle text-success ml5"></i>
                </template>
            </el-table-column>
            <!--操作下拉菜单-->
            <el-table-column
                    label="操作"
                    width="120"
                    align="center">
                <template slot-scope="scope">
                    <el-dropdown @command="dropdownCommand">
                        <el-button size="mini">
                            <i class="ti-settings"></i>
                            <span class="ti-angle-down"></span>
                        </el-button>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item
                                    :command="{type:'enable',id:scope.row.id,name:scope.row.payWay,row:scope.row}">
                                启用
                            </el-dropdown-item>
                            <el-dropdown-item
                                    :command="{type:'disable',id:scope.row.id,name:scope.row.payWay,row:scope.row}">
                                禁用
                            </el-dropdown-item>
                            <el-dropdown-item divided :command="{type:'edit',id:scope.row.id}">
                                修改
                            </el-dropdown-item>
                            <el-dropdown-item
                                    :command="{type:'delete',id:scope.row.id,payWay:scope.row.payWay,currency:scope.row.remark}">
                                删除
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </template>
            </el-table-column>
        </el-table>
    </el-row>
    <!--分页容器-->
    <el-row class="el-pagination-container">
        <el-pagination
                @size-change="pageSizeChange"
                @current-change="pageNumberChange"
                :current-page="pageForm.pageNumber"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="pageForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageForm.totalCount">
        </el-pagination>
    </el-row>
    <!--新增/修改按钮弹出的dialog-->
    <el-dialog
            :title="titlePopu==0?'新增支付方式':'修改支付方式'"
            :visible.sync="editDialogVisible"
            :close-on-click-modal="false"
            width="40%">
        <el-form :model="formData" ref="editForm" :rules="formRules" size="small" label-width="100px">
            <el-form-item prop="currencyId" label="币种">
                <el-select
                        v-model="formData.currencyId"
                        placeholder="请选择"
                        @change="payWayEnums"
                >
                    <el-option
                            v-for="item in currencies"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                            :disabled="item.id == 'default'">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="payWay" label="支付方式">
                <el-select
                        v-model="formData.payWay"
                        placeholder="请选择"
                >
                    <el-option
                            v-for="item in enums"
                            :key="item"
                            :label="item"
                            :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="logo" label="logo">
                <el-upload
                        class="avatar-uploader"
                        tabindex="5"
                        action="${base}/open/file/upload/image2"
                        name="Filedata"
                        :show-file-list="false"
                        :on-success="function(resp,file,fileList){return handlePicSuccess(resp,file,fileList,'logo')}">
                    <img v-if="formData.logo" :src="formData.logo" class="avatar">
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
            </el-form-item>
            <el-form-item prop="sort" label="序号">
                <el-input-number maxlength="100" :placeholder="titlePopu==0?'输入序号':'修改序号'"
                          v-model="formData.sort"
                          auto-complete="off"
                          type="text"
                >
                </el-input-number>
            </el-form-item>
            <el-form-item prop="minRechargeAmount" label="单次最低充值金额">
                <el-input maxlength="100" placeholder="为空则不验证"
                          v-model="formData.minRechargeAmount"
                          auto-complete="off"
                          type="number"
                >
                </el-input>
            </el-form-item>
            <el-form-item prop="maxRechargeAmount" label="单次最高充值金额">
                <el-input maxlength="100" placeholder="为空则不验证"
                          v-model="formData.maxRechargeAmount"
                          auto-complete="off"
                          type="number"
                >
                </el-input>
            </el-form-item>
            <el-form-item prop="minWithDrawAmount" label="单次最低提现金额">
                <el-input maxlength="100" placeholder="为空则不验证"
                          v-model="formData.minWithDrawAmount"
                          auto-complete="off"
                          type="number"
                >
                </el-input>
            </el-form-item>
            <el-form-item prop="maxWithDrawAmount" label="单次最高提现金额">
                <el-input maxlength="100" placeholder="为空则不验证"
                          v-model="formData.maxWithDrawAmount"
                          auto-complete="off"
                          type="number"
                >
                </el-input>
            </el-form-item>
            <el-form-item prop="disabled" label="启用状态">
                <el-switch
                        v-model="formData.disabled"
                        active-color="#ff4949"
                        inactive-color="#13ce66">
                </el-switch>
            </el-form-item>
        </el-form>
        <!--        确认/取消 提交修改按钮-->
        <span slot="footer" class="dialog-footer">
            <el-button @click="editDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="doEdit">确 定</el-button>
        </span>
    </el-dialog>
</div>
<script>
    new Vue({
        el: "#app",
        data: function () {
            var self = this;
            return {
                editDialogVisible: false,
                titlePopu: 0,
                tableData: [],
                pageForm: {
                    pageNumber: 1,
                    pageSize: 10,
                    totalCount: 0,
                    searchKeyword: "",
                },
                formData: {
                    payWay: "",
                    currencyId: "",
                    logo: "",
                    sort: "",
                    disabled: false,
                    minRechargeAmount: "",
                    maxRechargeAmount: "",
                    minWithDrawAmount: "",
                    maxWithDrawAmount: "",
                },
                formRules: {
                    payWay: [
                        {required: true, message: '请输入支付方式名称', trigger: 'blur'}
                    ],
                    currencyId: [
                        {required: true, message: '请选择币种', trigger: 'blur'}
                    ],
                    sort: [
                        {required: true, message: '请输入序号', trigger: 'blur'}
                    ],
                },
                currencies: [],
                enums: [],
            }
        },
        methods: {
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                $.post(base + "/platform/sys/payWay/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code == 0) {
                        self.tableData = data.data.list;
                        self.pageForm.totalCount = data.data.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            currencyList: function () {
                var self = this;
                $.post(base + "/platform/sys/currency/list", function (data) {
                    if (data.code == 0) {
                        self.currencies = data.data;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json")
            },
            payWayEnums: function () {
                var self = this;
                // 切换币种时清空支付方式
                this.$set(this.formData, 'payWay', '');
                $.post(base + "/platform/sys/payWay/enums", {currencyId: self.formData.currencyId}, function (data) {
                    if (data.code == 0) {
                        self.enums = data.data;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            doSearch: function () {
                this.pageForm.pageNumber = 1;
                this.pageData();
            },
            openAdd: function () {// 新建/修改User按钮逻辑
                var self = this;
                self.titlePopu = 0;
                this.editDialogVisible = true;
                //打开新增窗口,表单先清空
                this.formData = {};
                if (this.$refs["editForm"]) {
                    this.$refs["editForm"].resetFields();
                }
            },
            doEdit: function () { // 提交新增/修改
                var self = this;
                self.$refs["editForm"].validate(function (valid) {
                    if (valid) {
                        //titlePopu=0是新增,1是修改
                        if (self.titlePopu == 0) {
                            $.post(base + "/platform/sys/payWay/add", self.formData, function (data) {
                                if (data.code == 0) {
                                    self.$message({
                                        message: data.msg,
                                        type: 'success'
                                    });
                                    self.doSearch();
                                    self.editDialogVisible = false;
                                } else {
                                    self.$message({
                                        message: data.msg,
                                        type: 'error'
                                    });
                                }
                            }, "json");
                        } else {
                            $.post(base + "/platform/sys/payWay/editDo", self.formData, function (data) {
                                if (data.code == 0) {
                                    self.$message({
                                        message: data.msg,
                                        type: 'success'
                                    });
                                    self.doSearch();
                                    self.editDialogVisible = false;
                                } else {
                                    self.$message({
                                        message: data.msg,
                                        type: 'error'
                                    });
                                }
                            }, "json");
                        }
                    }
                });
            },
            dropdownCommand: function (command) {//监听下拉框事件
                var self = this;
                // 启用，禁用按钮
                if ("enable" == command.type || "disable" == command.type) {
                    $.post(base + "/platform/sys/payWay/" + command.type + "/" + command.id, {}, function (data) {
                        if (data.code == 0) {
                            self.$message({
                                message: data.msg,
                                type: 'success'
                            });
                            if ("disable" == command.type) {
                                command.row.disabled = true;
                            }
                            if ("enable" == command.type) {
                                command.row.disabled = false;
                            }
                        } else {
                            self.$message({
                                message: data.msg,
                                type: 'error'
                            });
                        }
                    }, "json");
                }
                // 修改按钮
                if ("edit" == command.type) {
                    $.post(base + "/platform/sys/payWay/edit/" + command.id, {}, function (data) {
                        if (data.code == 0) {
                            if (self.$refs["editForm"]) {// 清空校验提示
                                self.$refs["editForm"].resetFields();
                            }
                            self.formData = data.data;// 加载后台表单数据
                            self.editDialogVisible = true;// 打开编辑窗口
                            self.titlePopu = 1;
                        } else {
                            self.$message({
                                message: data.msg,
                                type: 'error'
                            });
                        }
                    }, "json");
                }
                // 删除按钮
                if ("delete" == command.type) {
                    self.$confirm('此操作将删除 ' + command.payWay + '(' + command.currency + ')', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        callback: function (a, b) {
                            if ("confirm" == a) {//确认后再执行
                                $.post(base + "/platform/sys/payWay/delete/" + command.id, {}, function (data) {
                                    if (data.code == 0) {
                                        self.$message({
                                            message: data.msg,
                                            type: 'success'
                                        });
                                        self.doSearch();
                                    } else {
                                        self.$message({
                                            message: data.msg,
                                            type: 'error'
                                        });
                                    }
                                }, "json");
                            }
                        }
                    });
                }
            },
            handlePicSuccess: function (response, file, fileList, attrName) {// 上传图片
                if (response.code == 0) {
                    // 对象属性直接赋值不会触发试图更新，采用 Vue.set 、this.$set或者Object.assign({}，this.obj)创建新对象
                    // 或者也可以定义一个 refresh 属性 ，当数据发生改变时，该属性同时变化，也会触发视图更新
                    // this.formData.site_logo =response.data;
                    this.$set(this.formData, attrName, response.data);
                } else {
                    this.$set(this.formData, attrName, "");
                }
            },
        },
        created: function () {
            // 获取币种列表
            this.currencyList();
            this.pageData();
        }
    });
</script>

<!--#
}
#-->